<?php
namespace app\index\model;
use app\common\model\Base;

class Zaixian extends Base
{  
    //记录在线时长
    public function setOnlineTime($username,$login_time,$time_lingt=0,$login_ip,$login_url) {
        //return true;
        $res = Zaixian::name('zaixian')
                ->bind(['username'=>$username,'login_time'=>$login_time,'time_lingt'=>$time_lingt,'login_ip'=>$login_ip,'login_url'=>$login_url])
                ->insert(['username'=>':username','login_time'=>':login_time','time_lingt'=>':time_lingt','login_ip'=>':login_ip','login_url'=>':login_url']);
        return $res;
    }
    //更新在线时长等信息
    public function updateOnlineTime($id,$username,$login_time,$time_lingt=0,$login_ip,$login_url) {
        //return true;
        $res = Zaixian::name('zaixian')
                ->bind(['id'=>$id,'username'=>$username,'login_time'=>$login_time,'time_lingt'=>$time_lingt,'login_ip'=>$login_ip,'login_url'=>$login_url])
                ->where('id',':id')
                ->update(['username'=>':username','login_time'=>':login_time','time_lingt'=>':time_lingt','login_ip'=>':login_ip','login_url'=>':login_url']);
        return $res;
    }
    //仅更新在线时长
    public function updateOnlineTimeOnly($id,$time_lingt=0) {
        //return true;
        $res = Zaixian::name('zaixian')
        ->bind(['id'=>$id,'time_lingt'=>$time_lingt])
        ->where('id',':id')
        ->update(['time_lingt'=>':time_lingt']);
        return $res;
    }
    //删除时长信息
    public function delOnlineTime($username) {
        //return true;
        $res = Zaixian::name('zaixian')->bind(['username'=>$username])->where('username',':username')->delete();
        return $res;
    }

}